package com.qianchang.microfinance.view;

import android.os.Bundle;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.dm.library.utils.StringUtils;
import com.qianchang.microfinance.R;
import com.qianchang.microfinance.view.base.BaseActivity;

import butterknife.BindView;
import butterknife.ButterKnife;

public class WelComeToUrlActivity extends BaseActivity {

    @BindView(R.id.web_view)
    WebView webView;
    private String url;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wel_come_to_url);
        ButterKnife.bind(this);
        Bundle bundle = getBundle();
        if (null != bundle) {
            url = bundle.getString("url");
        }
        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webView.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onReceivedTitle(WebView view, String title) {
                super.onReceivedTitle(view, title);
                WelComeToUrlActivity.this.setTitleName(title);
            }
        });
        webView.setWebViewClient(new WebViewClient() {
            public boolean shouldOverrideUrlLoading(WebView view, String url) { // 重写此方法表明点击网页里面的链接还是在当前的webview里跳转，不跳到浏览器那边
                if (null != url) {
                    view.loadUrl(url);
                }
                return true;
            }
        });

        if (!StringUtils.isEmptyOrNull(url))
            webView.loadUrl(url);

    }


}
